#include <stdlib.h>
#include <stdio.h>
#include "subband_proc.h"

int main(int argc, char *argv[])
{
    int frame_size = 320; // 20ms
    FILE *fidmic = fopen(argv[1], "rb");
    FILE *fidaec = fopen(argv[2], "wb");

    fseek(fidmic, 0, SEEK_END); int d2 = ftell(fidmic);
    fseek(fidmic, 0, SEEK_SET); int d1 = ftell(fidmic);	
    int frames = (d2-d1)/sizeof(short)/frame_size; 
    printf("total frames = %d\n", frames);

    short *xbuf = (short *)calloc(frame_size, sizeof(short));
    short *ybuf = (short *)calloc(frame_size, sizeof(short));

    void *handle = subband_create(frame_size);

    for (int n=0; n<frames; n++) {
        fread(xbuf, sizeof(short), frame_size, fidmic);
        subband_process(handle, NULL, xbuf, ybuf);
        fwrite(ybuf, sizeof(short), frame_size, fidaec);
    }

    subband_destory(handle);
    fclose(fidaec); fclose(fidmic);
    free(xbuf); free(ybuf);
    return 0;
}